module.exports = (api, options) => {
  api.postProcessFiles((files) => {
    useDirective(files);
  });
  api.render("./template");
};

function useDirective(files) {
  const routerFile = "src/main.js";
  let routerStr = files[routerFile];
  let imp = 'import directive from "@/directive";';
  let use = "Vue.use(directive);";

  if (
    routerStr &&
    routerStr.indexOf(imp) === -1 &&
    routerStr.indexOf(use) === -1
  ) {
    files[routerFile] = routerStr.replace(
      /(import Vue from "vue";?[^\n]+)/,
      `$1\n${imp}\n${use}\n`
    );
  }
}
